//
//  KYCollectionView.m
//  kuaiyi
//
//  Created by 杨亮 on 16/3/11.
//  Copyright © 2016年 kuaiyi. All rights reserved.
//

#import "KYCollectionView.h"
#import "Header.h"
#import "KYClassCell.h"
#import "KYClassModel.h"


@interface KYCollectionView ()<UICollectionViewDataSource>
@property (nonatomic, strong)NSArray *classModel;
@end

@implementation KYCollectionView
-(NSArray *)classModel{
    if (!_classModel) {
        _classModel = [KYClassModel getClassModel];
    }
    return _classModel;
}
-(instancetype)init{
    if (self = [super initWithFrame:CGRectZero collectionViewLayout:[[UICollectionViewFlowLayout alloc]init]]) {
        self.backgroundColor = [UIColor whiteColor];
        
        UICollectionViewFlowLayout *flowLayout = (UICollectionViewFlowLayout *)self.collectionViewLayout;
        [self registerClass:[KYClassCell class] forCellWithReuseIdentifier:collectionViewCellID];
        flowLayout.itemSize = CGSizeMake(itemWith, itemWith);
        flowLayout.minimumInteritemSpacing = 0;
        flowLayout.minimumLineSpacing = 0;
        self.dataSource = self;
    }
    return self;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return self.classModel.count;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    KYClassCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:collectionViewCellID forIndexPath:indexPath];
//    cell.backgroundColor = indexPath.item % 2 == 0 ? [UIColor greenColor]:[UIColor yellowColor];
//    KYClassModel *model = self.classModel[indexPath.item];
    cell.classModel = self.classModel[indexPath.item];
    return cell;
}
//点击没反应,只能通过controller
//-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
//    NSString *name = self.classModel[indexPath.item];
//    [[NSNotificationCenter defaultCenter]postNotificationName:@"collectionViewCellSelected" object:nil userInfo:@{@"name":name}];
//}
@end
